package scope;

import hello.UserServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
    public static void main(String[] args) {

        //被spring管理的bean，默认作用域是单利（singleton）

        // 容器启动的时候，所有的单利bean都会被实例化出来

        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-scope.xml");

/*
        UserServiceImplForScope user = context.getBean("user", UserServiceImplForScope.class);
        System.out.println(user.hashCode());
        user.m();

        UserServiceImplForScope user2 = context.getBean("user", UserServiceImplForScope.class);
        System.out.println(user2.hashCode());
        user2.m();
        System.out.println(user ==user2);*/


        System.out.println("**********************");
        //原形作用域的bean，在容器启动时“没有”被实例化出来的
        //每个用getBean获取对象的时候，就创建一个新的对象出来
        UserServiceImplForScope user3 = context.getBean("user3", UserServiceImplForScope.class);
        UserServiceImplForScope user4= context.getBean("user3", UserServiceImplForScope.class);

    }
}
